<?php

namespace App\Models\Products;

use App\Models\Customers\Customer;
use App\Models\Order\OrderOption;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

/**
 * Class Review
 * @property Customer customer
 * @property Collection|OrderOption[] orderOptions
 * @property string author
 *
 * @property-write string|null customer_image
 * @property-write string|null customer_fullname
 * @property string review_id
 *
 * @package App\Models\Products
 *
 * @mixin Builder
 */

class Review extends Model
{
    const DEFAULT_COMMENT_COUNT = 0;
    const DEFAULT_FAVOURABLE_COMMENT_SCORE = 3;
    const PRODUCT_DETAIL_COMMENT_COUNT = 2;    // app商品详情页，商品评论的条数。

    const REVIEW_STATUS_ON = 1; // 开启商品评论
    const REVIEW_STATUS_OFF = 0; // 关闭商品评论
    const ORDER_PRODUCT_REVIEW_HAS = 1; // order_product有评价
    const ORDER_PRODUCT_REVIEW_NO = 0; // order_product没有评价

    const REVIEW_RATING_MAP = [1, 2, 3, 4, 5];

    protected $table = 'review';
    protected $guarded = [];

    public $timestamps = false;

    protected $primaryKey = 'review_id';
    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function customer()
    {
        return $this->belongsTo(Customer::class, 'customer_id', 'customer_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function orderOptions()
    {
        return $this->hasMany(OrderOption::class, 'order_product_id', 'order_product_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function reviewImages()
    {
        return $this->hasMany(ReviewImage::class, 'review_id', 'review_id');
    }
}
